import machine
import time
import _thread
import os
import network
from machine import Pin, PWM

led = Pin(2, Pin.OUT)
led.value(1)
led2 = PWM(Pin(4))
led2.freq(1000)
led2.duty(0)

nat = network.WLAN(network.STA_IF)
nat.active(True)
print("Starting")

with open('wifi data.txt', 'w') as file:  # 打开文件，如果文件不存在会创建
    file.write('time:' + str(time.time()) + '\n')  # 写入字符串
    file.write('---------------------\n')
    print('time:' + str(time.time()))
def net_fund():
    return nat.scan()

def txt():
    data=str(net_fund())
    led.value(1)
    with open('data.txt', 'a') as file:  # 打开文件，追加内容
        file.write(data + '\n') 
        print('---------------------')
        print("Write:",data)
        print('---------------------\n')
    led.value(0)

def led_link():
    for i in range(0, 1023,10):
        led2.duty(i)
        time.sleep_ms(1)

while True:
    led.value(0)
    led_link()
    led.value(1)
    txt()



